<?php
/**
 * <https://y.st./>
 * Copyright © 2018 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'Addressing and packet lengths',
	'<{subtitle}>' => 'Written in <span title="Communications and Networking">CS 2204</span> by <a href="https://y.st./">Alex Yst</a>, finalised on 2018-05-09',
	'<{copyright year}>' => '2018',
	'takedown' => '2017-11-01',
	'<{body}>' => <<<END
<h2>Subnets</h2>
<h3><code>10.0.130.0/23</code>: <code>10.0.130.23</code>, <code>10.0.129.1</code>, <code>10.0.131.12</code>, <code>10.0.132.7</code></h3>
<p>
	The first thing we need to do to determine which of the given $a[IP] addresses are a part of the given subnet is to figure out how much of the given subnet $a[IP] is the prefix.
	The number after the slash is the number of bits that identify the subnet, with the remaining bits identifying the host (Dordal, 2014).
	Each of the four numbers in an $a[IPv4] address represent eight bits, so using the <code>/23</code> subnet mask, the separation point is in the third number, with seven bits being part of the network portion of the address and one bit being part of the host portion of the address.
	<code>130</code> in binary is <code>0b10000010</code>, so the third number of any $a[IPv4] address within the subnet will have it&apos;s first seven bits be <code>0b1000001</code>.
	The final bit can be flipped, so the number needs to be <code>130</code> or <code>131</code>.
	All $a[IPv4] addresses in the form &quot;10.0.x.*&quot; where x is <code>130</code> or <code>131</code> are a part of the subnet and all other addresses are not.
	<strong>That means that <code>10.0.130.23</code> and <code>10.0.131.12</code> are within the <code>10.0.130.0/23</code> subnet, but <code>10.0.129.1</code> and <code>10.0.132.7</code> are not.</strong>
</p>
<h3><code>10.0.132.0/22</code>: <code>10.0.130.23</code>, <code>10.0.135.1</code>, <code>10.0.134.12</code>, <code>10.0.136.7</code></h3>
<p>
	We can apply the same process as last time.
	This time, one less bit is a part of the subnet portion of the address.
	<code>132</code> in binary is <code>0b10000100</code>.
	With two flippable bits instead of one, we add three to the range instead of one.
	Addresses within this subnet are in the form &quot;10.0.x.*&quot; where x is an integer from <code>132</code> (<code>0b10000100</code>) to <code>135</code> (<code>0b10000111</code>).
	<strong><code>10.0.135.1</code> and <code>10.0.134.12</code> are a part of the <code>10.0.132.0/22</code> subnet, but <code>10.0.130.23</code> and <code>10.0.136.7</code> are not.</strong>
</p>
<h3><code>10.0.64.0/18</code>: <code>10.0.65.13</code>, <code>10.0.32.4</code>, <code>10.0.127.3</code>, <code>10.0.128.4</code></h3>
<p>
	This time, the network portion is eighteen bits long, which extends two bits into the third number.
	<code>64</code> in binary is <code>0b01000000</code>, so any third number in the <code>64</code> (<code>0b01000000</code>) to <code>127</code> (<code>0b1111111</code>) range is acceptable as x in the pattern &quot;10.0.x.*&quot;.
	<strong><code>10.0.65.13</code> and <code>10.0.127.3</code> are part of the <code>10.0.64.0/18</code> subnet, but <code>10.0.32.4</code> and <code>10.0.128.4</code> are not.</strong>
</p>
<h3><code>10.0.168.0/21</code>: <code>10.0.166.1</code>, <code>10.0.170.3</code>, <code>10.0.174.5</code>, <code>10.0.177.7</code></h3>
<p>
	With the network portion of the address being twenty-on bits long, it extends five bits into the third number.
	<code>168</code> in binary is <code>0b10101000</code>, so the third number of an address within this subnet can be anywhere from <code>168</code> (<code>0b10101000</code>) to <code>175</code> (<code>0b10101111</code>).
	<strong><code>10.0.170.3</code> and <code>10.0.174.5</code> are within this subnet, but <code>10.0.166.1</code> and <code>10.0.177.7</code> are not.</strong>
</p>
<h3><code>10.0.0.64/26</code>: <code>10.0.0.125</code>, <code>10.0.0.66</code>, <code>10.0.0.130</code>, <code>10.0.0.62</code></h3>
<p>
	This time, the network portion of the address is twenty-six bits long, which extends two bits into the final number.
	<code>64</code> in binary is <code>0b01000000</code>.
	For this subnet, addresses match the pattern &quot;10.0.0.x&quot;, where x is an integer from <code>64</code> (<code>0b01000000</code>) to <code>127</code> (<code>0b01111111</code>).
	<strong><code>10.0.0.125</code> and <code>10.0.0.66</code> are a part of this subnet, but <code>10.0.0.130</code> and <code>10.0.0.62</code> are not.</strong>
</p>
<h2>Notation conversions</h2>
<h3><code>255.255.240.0</code></h3>
<p>
	To convert a subnet mask to /k notation, we just need to count the number of <code>0b1</code> bits before the <code>0b0</code> bits begin.
	<code>255</code> is <code>0b11111111</code> and <code>0</code> is <code>0b00000000</code>, so if those are the only two numbers in the $a[IPv4] subnet mask, we just multiply the number of instances of <code>255</code> by eight and we&apos;re done.
	If there&apos;s a third number though, we need to count the number of <code>0b1</code> bits and add those in as well.
	<code>240</code> in binary is <code>0b11110000</code> so we have two times eight plus four.
	<strong>This subnet mask is the same as <code>/20</code>.</strong>
</p>
<h3><code>255.255.248.0</code></h3>
<p>
	<code>248</code> in binary is <code>0b11111000</code>, so we have five <code>0b1</code> bits in the third number.
	<strong>This subnet mask is the same as <code>/21</code>.</strong>
</p>
<h3><code>255.255.255.192</code></h3>
<p>
	This time, the cut-off point is in the fourth number.
	<code>192</code> is <code>0b11000000</code> in binary, so we have two bits that are part of the network portion, as well as the three times eight bits from the first three numbers.
	<strong>That means that this subnet mask is the same as <code>/26</code>.</strong>
</p>
<h3><code>/20</code></h3>
<p>
	We converted <code>255.255.240.0</code> to <code>/20</code>, so as there&apos;s a one-to-one matching between these two notations, it stands to reason that if we want to convert <code>/20</code> into a subnet mask, we&apos;ll get back <code>255.255.240.0</code>.
	If we hadn&apos;t just converted the other way though, we&apos;d look at the number of bits specified as the prefix and convert from binary to decimal.
	First, we look at the number of multiples of eight.
	We&apos;re basically performing integer division.
	Two eights will fit into twenty, so we start the mask with two instances of <code>255</code>.
	Next, we perform modulo division.
	twenty modulo eight is four, so the next number in the mask begins with four <code>0b1</code> bits, with the remaining bits of the mask being set to <code>0b0</code>.
	<code>0b11110000</code> in binary is <code>240</code> in decimal, so <strong><code>/20</code> is equal to the <code>255.255.240.0</code> subnet mask.</strong>
</p>
<h3><code>/22</code></h3>
<p>
	Again, we need to perform integer division and modulo division.
	<code>22</code> divided by eight, restricted to an integer is two.
	<code>22</code> modulo eight is six.
	<code>0b11111100</code> in binary is <code>252</code> in decimal.
	<strong>Therefore, <code>/22</code> is equal to the <code>255.255.252.0</code> subnet mask.</strong>
</p>
<h3><code>/27</code></h3>
<p>
	<code>27</code> divided by eight, restricted to an integer is three.
	<code>27</code> modulo eight is three.
	<code>0b11100000</code> in binary is <code>224</code> in decimal.
	<strong>Therefore, <code>/27</code> represents the <code>255.255.255.244</code> subnet mask.</strong>
</p>
<h2>Packets within packets, and minimum lengths</h2>
<p>
	The book tells us that the minimum packet size in Ethernet is sixty-four bytes.
	That number includes the Ethernet headers though; the book goes on to tell us that the payload portion (which is what will carry the $a[TCP] packet) of a minimum-length Ethernet packet is only forty-six bytes long (Dordal, 2014).
	Additionally, the book informs us that an $a[IPv6] header is forty bits long, mentioning that it&apos;s double the size of an $a[IPv4] header (Dordal, 2014).
	That makes an $a[IPv4] header twenty bytes long, which matches the length implied by the diagram of another section of the book.
	As the assignment states, a $a[TCP] header is included as well, which takes up another twenty bytes.
	<strong>Putting this all together, we see that an $a[IPv4] acknowledgement packet is six bytes short of the Ethernet minimum, and must be padded.
	An $a[IPv4] acknowledgement packet is sixty bytes long though (including the $a[TCP] header, which isn&apos;t technically a part of the $a[IPv6] packet but still adds to the size of the Ethernet packet payload), which meets the minimum Ethernet packet length requirements.</strong>
</p>
<h2>Retrying addresses in $a[ARP] caches</h2>
<p>
	$a[ARP] is designed to take an $a[IP] address and find the associated $a[LAN] address (Dordal, 2014).
	(In Ethernet, this would be the $a[MAC] address.)
	When retrying an expired address from the cache, the host is first supposed to try a unicast transmission to the last-known $a[LAN] address associated with that $a[IP] address.
	If the receiver isn&apos;t present or doesn&apos;t hold that address any longer, it&apos;ll ignore the request, at which point the querying host will try a broadcast request.
	<strong>If the $a[IP] address has changed hands and now refers to a different machine, any number of unicast requests (which would be sent to the former holder of the address) will fail, but a broadcast request should succeed (as the request will make it to all machines, including the newly-correct one).</strong>
</p>
<div class="APA_references">
	<h2>References:</h2>
	<p>
		Dordal, P. (2014). 1.10 IP - Internet Protocol. Retrieved from <a href="https://intronetworks.cs.luc.edu/current/html/intro.html#ip-internet-protocol"><code>https://intronetworks.cs.luc.edu/current/html/intro.html#ip-internet-protocol</code></a>
	</p>
	<p>
		Dordal, P. (2014). 2.1.5 The Slot Time and Collisions. Retrieved from <a href="https://intronetworks.cs.luc.edu/current/html/ethernet.html#the-slot-time-and-collisions"><code>https://intronetworks.cs.luc.edu/current/html/ethernet.html#the-slot-time-and-collisions</code></a>
	</p>
	<p>
		Dordal, P. (2014). 8.1 The IPv6 Header. Retrieved from <a href="https://intronetworks.cs.luc.edu/current/html/ipv6.html#the-ipv6-header"><code>https://intronetworks.cs.luc.edu/current/html/ipv6.html#the-ipv6-header</code></a>
	</p>
	<p>
		Dordal, P. (2014). 7.9 Address Resolution Protocol: ARP. Retrieved from <a href="https://intronetworks.cs.luc.edu/current/html/ipv4.html#address-resolution-protocol-arp"><code>https://intronetworks.cs.luc.edu/current/html/ipv4.html#address-resolution-protocol-arp</code></a>
	</p>
</div>
END
);
